import unittest
from parameterized import parameterized
import page
from base import log
from page.page_app_login import PageAppLogin
from page.page_app_order import PageAppOrder
from utils import GetDriver, read_json


class TestAppLogin(unittest.TestCase):
    def setUp(self) -> None:
        # 获取driver
        self.driver = GetDriver.get_app_driver()
        # 获取登录实例
        self.login = PageAppLogin(self.driver)
        # 获取下单实例
        self.order = PageAppOrder(self.driver)

    def tearDown(self) -> None:
        self.driver.quit()

    @parameterized.expand(read_json("login_order.json", "order"))
    def test01_login_ok(self, search_value, pay_pwd, nick):
        try:
            self.login.page_app_login("18059705367", "123456")
            nickname = self.login.page_app_get_nickname()
            print("登录昵称为:", nickname)
            # 断言昵称与登录昵称一致
            self.assertEqual(nick, nickname)
            self.order.page_app_order(search_value, pay_pwd)
            order_on = self.order.page_app_get_order_num()
            print("订单号为:", order_on)
            # 记录订单编号,做断言使用
            page.order_on = order_on[5:]
            log.info(f"------------------app下单成功,订单编号为:{page.order_on}-----------------")
        except Exception as err:
            print("出现了错误:", err)
            log.error(err)
            # 截图
            self.order.base_screenshot()
            raise
